// 班级管理相关API接口
import axios from 'axios'

// 创建axios实例
const api = axios.create({
  baseURL: 'http://localhost:9010',
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json'
  }
})

// 获取班级列表 (POST方法)
export const getClassList = async (params = {}) => {
  try {
    const response = await api.post('/api/class/list', params)
    return {
      success: true,
      data: response.data.data,
      total: response.data.data.total,
      message: '获取班级列表成功'
    }
  } catch (error) {
    console.error('获取班级列表失败:', error)
    return {
      success: false,
      data: [],
      total: 0,
      message: '获取班级列表失败'
    }
  }
}

// 获取班级详情 (POST方法)
export const getClassDetail = async (params) => {
  try {
    const response = await api.post('/api/class/getById', params)
    return {
      success: true,
      data: response.data.data,
      message: '获取班级详情成功'
    }
  } catch (error) {
    console.error('获取班级详情失败:', error)
    return {
      success: false,
      data: null,
      message: '获取班级详情失败'
    }
  }
}

// 更新班级 (POST方法)
export const updateClass = async (classData) => {
  try {
    const response = await api.post('/api/class/update', classData)
    return {
      success: true,
      data: response.data.data,
      message: '更新班级成功'
    }
  } catch (error) {
    console.error('更新班级失败:', error)
    return {
      success: false,
      data: null,
      message: '更新班级失败'
    }
  }
}

// 删除班级 (POST方法)
export const deleteClass = async (params) => {
  try {
    const response = await api.post('/api/class/delete', params)
    return {
      success: true,
      message: '删除班级成功'
    }
  } catch (error) {
    console.error('删除班级失败:', error)
    return {
      success: false,
      message: '删除班级失败'
    }
  }
}
